package com.zgkj.Zip.tools;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.httpclient.params.HttpClientParams;

public class HttpClientUtil_passwd {

	public static String sendAndRecv(String uri,String charset,String json){
		HttpClientParams clientParams = new HttpClientParams();
		clientParams.setSoTimeout(45000);
		clientParams.setContentCharset("utf-8");
		HttpClient  client = new HttpClient(clientParams);
		PostMethod method = new PostMethod(uri);
		try{
			method.setRequestEntity(new StringRequestEntity(json,"text/json",charset));
			int result = client.executeMethod(method);
			if(result == 200){
				InputStream is = method.getResponseBodyAsStream();
				ByteArrayOutputStream baos = new ByteArrayOutputStream();
			    int   i=-1;
			    while((i=is.read())!=-1){
			    	baos.write(i);
			    }
			    String response =baos.toString(charset);
				return response;
			}else{
				System.out.println(result);
			}
		}catch (Exception e) {
			e.printStackTrace();
		}finally{
			method.releaseConnection();
		}

		return "-1";
	}


	public static void main(String[] args) throws Exception {
		for (int i = 0; i <10000; i++) {
			long start_time = System.currentTimeMillis();
			System.out.println(i);
			long end_time = System.currentTimeMillis();
			System.out.println("处理耗时："+(end_time - start_time)+"毫秒");
		}
	}
}
